package com.flyme.module.base.provider.controller;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysUserexaminationRemoteService;
import com.flyme.module.base.client.dto.SysUserexaminationDto;
import com.flyme.module.base.client.entity.SysUserexamination;
import com.flyme.module.base.provider.service.SysExatimeService;
import com.flyme.module.base.provider.service.SysUserexaminationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 考试管理
 * @author zyh
 * @date 2020-3-26
 */
@Api(tags = "考试")
@RestController
public class SysUserexaminationController extends BaseController<SysUserexaminationService, SysUserexamination> implements SysUserexaminationRemoteService {

    @Autowired
    private SysExatimeService exatimeService;

    /**
     * 用户考试记录列表
     * @return
     */
    @Override
    public ResultBody list(PagerInfo pagerInfo, SysUserexaminationDto userexamination) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("u.*,cc.certificateName userCertificateName,user.userName,user.idCard,certificate.certificateName,exam.examName," +
                "exam.examinationCode, exam.examType examType2, user.cardLiveImg");
        cq.like("user.userName", userexamination.getUserName());
        cq.like("user.idCard", userexamination.getIdCard());
        cq.like("exam.examName", userexamination.getExamName());
        if(!userexamination.getExamStatus().equals(100)){
            cq.eq("u.examStatus", userexamination.getExamStatus());
        }
        if(!userexamination.getExamType().equals(100)){
            cq.eq("exam.examType", userexamination.getExamType());
        }
        cq.ne("examStatus", 0);
        cq.ne("examStatus", 3);
        cq.createAlias("user", "user");
        cq.createAlias("exam", "exam");
        cq.createAlias("certificate", "certificate");
        cq.createAlias("usercertificate", "usercertificate");
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    /**
     * 删除场次考试时间
     */
    @Override
    public ResultBody exaTimeList(@PathVariable String exatimeId) {
        String[] ids = exatimeId.split(",");
        CriteriaQuery cq = new CriteriaQuery<EntityMap>();
        cq.select("*, examseason.childexamName");
        cq.in("e.id", ids);
        cq.createAlias("examseason", "examseason");
        List<EntityMap> list = exatimeService.listEntityMaps(cq);
        return ResultBody.success(list);
    }


}
